<template>
	<view>
		<view v-if="inputflag" @click="hideKeyboard" class="wdh-100 columnbox info-input"
			:style="{'height':windowHeight}">
			<!-- 键盘输入框 -->

			<view @click.stop="" class="one-yc rowbox spb" style="margin-left: 20rpx;">
				<view class="rowbox yc-name-input">{{searchvalueinput}} <text class="input-line">｜</text>
					<text v-if="searchvalueinput==''" style="color: #bcbcbc ;">请输入药材简拼</text>
				</view>
				<!-- <input @input="searchYaoCai" class="yc-name" placeholder="请输入药材简拼" v-model="searchvalue" /> -->
			</view>
			<view class="wdh-100 keybord-box columnbox" @click.stop="">
				<view class="keyboard-type rowbox">
					<view class="rowbox keyboard-type-list">
						<view @click="curType=item.value" class="one-keyboard-type rowbox"
							:class="{'sel-type':item.value==curType}" v-for="(item,index) in typeList" :key='index'>
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="wdh-100 columnbox" style="background: #fff;">
					<!-- 快速录方 -->
					<template v-if="curType==1">
						<scroll-view scroll-x style="width: 100%;white-space: nowrap;">
							<view @click="chooseYc(item)" style="display: inline-block" v-for="(item,index) in jisuList"
								:key='index'>
								<view class="columnbox one-s-yc">
									<view>{{item.name}}</view>
									<view>{{item.price}}元/g</view>
								</view>
							</view>
						</scroll-view>
						<view class="wdh-100 rowbox key-bord" style="padding-bottom: 20rpx;">
							<input :adjust-position="false" @blur="KeyBoardHeight=0"
								@keyboardheightchange="getKeyBoardHeight" v-model="jisuValue" @input="searchYaocai"
								class="jisu-keyboard" placeholder="请输入" :focus="true" />
						</view>
						<view class="wdh-100" :style="{'height':KeyBoardHeight+'px'}"></view>
					</template>
					<!-- 常用药 -->
					<template v-if="curType==2">
						<scroll-view @scrolltolower="loadChangyong" scroll-y class="wdh-100"
							style="height:475rpx ;padding: 20rpx 0;box-sizing: border-box;">
							<view class="wdh-100" style="display: flex;flex-wrap: wrap;justify-content: flex-start;">
								<view @click="chooseYc(item)" class="rowbox yc-changyong"
									v-for="(item,index) in changyongList" :key='index'>
									{{item.name}}
								</view>
							</view>
						</scroll-view>
					</template>
					<!-- 键盘 -->
					<template v-if="curType==3">
						<scroll-view scroll-x style="width: 100%;white-space: nowrap;">
							<view @click="chooseYc(item)" style="display: inline-block"
								v-for="(item,index) in searchResult" :key='index'>
								<view class="columnbox one-s-yc">
									<view>{{item.name}}</view>
									<view>{{item.price}}元/g</view>
								</view>
							</view>
							<!-- <view style="display: inline-block" v-if="searchResult.length==0">
								<view class="columnbox one-s-yc">
									<view style="color: #fff;">1</view>
									<view style="color: #fff;">1</view>
								</view>
							</view> -->
						</scroll-view>
						<view class="columnbox key-bord wdh-100">
							<view class="rowbox wdh-100">
								<view @click="inputValue(item)" class="rowbox one-letter"
									v-for="(item,index) in keybord.slice(0, 10)" :key='index'>
									{{item}}
								</view>
							</view>
							<view class="rowbox wdh-100">
								<view @click="inputValue(item)" class="rowbox one-letter"
									v-for="(item,index) in keybord.slice(10, 19)" :key='index'>
									{{item}}
								</view>
							</view>
							<view class="rowbox wdh-100" style="position: relative;">
								<view @click="inputValue(item)" class="rowbox one-letter"
									v-for="(item,index) in keybord.slice(19, 26)" :key='index'>
									{{item}}
								</view>
								<view class="rowbox delet-icon" @click="deletLetter">
									<image src="/static/img/delet-icon.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
					</template>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputflag: false,
				ycList: [], //药材列表
				searchvalue: '',
				keybord: ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
					'Z', 'X', 'C', 'V', 'B', 'N', 'M'
				],
				searchvalueinput: '', //输入的搜索内容
				searchResult: [], //搜索结果
				typeList: [{
						value: 3,
						name: '键盘'
					}, {
						value: 1,
						name: '极速录方'
					},
					{
						value: 2,
						name: '常用药库'
					},
				],
				curType: 3,
				pageNo: 1,
				jisuValue: '',
				jisuList: [], //极速录入方
				KeyBoardHeight: 0,
				changyongList: [], //常用药
				totalCount: 0, //常用药总数
			};
		},
		props: {
			windowHeight: {
				type: String,
				default: '100vh'
			},
			sotreId: {
				type: Number,
				default: 0
			},
			jixingid: {
				type: Number,
				default: 0
			},
		},
		mounted() {
			this.getChangyongList()
		},

		methods: {
			hideKeyboard() {
				this.inputflag = false
				this.$emit('cancel', true)
			},
			loadChangyong() {
				if (this.changyongList.length < this.totalCount) {
					this.pageNo++
					this.getChangyongList()
				}
			},
			getKeyBoardHeight(e) {
				this.KeyBoardHeight = e.detail.height
			},
			// 极速录方
			searchYaocai() {
				if (this.jisuValue != '') {
					this.$req.post('/doctor/chinesedrugzw', {
						name: this.jisuValue,
						pharmacyid: this.sotreId,
						jixingid: this.jixingid
					}).then(res => {
						this.jisuList = res.data.data
					})
				}
			},
			getChangyongList() {
				this.$req.post('/doctor/chinesedrugcy', {
					doctorid: uni.getStorageSync('uid'),
					pageNo: this.pageNo,
					pageSize: 20,
					pharmacyid: this.sotreId,
					jixingid: this.jixingid
				}).then(res => {
					this.changyongList = this.changyongList.concat(res.data.data.data)
					this.totalCount = res.data.data.totalCount
				})
			},
			initData() {
				this.inputflag = true
			},
			// 键盘输入
			inputValue(v) {
				if (this.searchvalueinput.length < 10) {
					this.searchvalueinput += v
					this.$req.post('/doctor/chinesedrugs', {
						name: this.searchvalueinput,
						pharmacyid: this.sotreId,
						jixingid: this.jixingid
					}).then(res => {
						this.searchResult = res.data.data
					})
				}
			},
			//删除输入
			deletLetter() {
				if (this.searchvalueinput != '') {
					if (this.searchvalueinput.length == 1) {
						this.searchvalueinput = ''
						this.searchResult = []
					} else {
						this.searchvalueinput = this.searchvalueinput.substring(0, this.searchvalueinput.length - 1)
						this.$req.post('/doctor/chinesedrugs', {
							name: this.searchvalueinput,
							pharmacyid: this.sotreId
						}).then(res => {
							this.searchResult = res.data.data
						})
					}
				}
			},
			chooseYc(v) {
				this.$emit('change', {
					chinesedrug: v.name,
					chinesedrugid: v.id,
					gram: 1,
					yaofangid: '',
					price: v.price
				})
				this.inputflag = false
				this.searchvalueinput = ''
				this.searchResult = []
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background: #F5F8FB;
		justify-content: flex-start;
		font-family: PingFang SC;
	}

	.yc-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: flex-start;
		padding-left: 20rpx;
		box-sizing: border-box;
		width: 100%;
	}


	.one-yc {
		margin-right: 20rpx;
		background: #fff;
		padding: 20rpx 20rpx;
		border-radius: 10rpx;
		margin-top: 20rpx;
		width: calc((100% - 40rpx)/2);
		align-items: flex-start;
	}

	.yc-name,
	.yc-name-input {
		font-weight: bold;
		font-size: 26rpx;
		color: #0E0E0E;
		margin-left: 20rpx;
	}

	.yc-name-input {
		font-size: 32rpx;
		font-weight: normal;
	}

	.yc-weight {
		font-weight: 500;
		font-size: 22rpx;
		color: #939BA7;
	}

	/deep/.uni-input-input {
		font-size: 24rpx;
	}

	.info-input {
		background: rgba(#000, 0.4);
		position: fixed;
		top: var(--window-top);
		left: 0;
		z-index: 9;
		justify-content: space-between;
		align-items: flex-start;
		box-sizing: border-box;
	}

	.keybord-box {
		width: 100%;
		// background: #fff;
		padding-bottom: 0;

		.one-s-yc {
			padding: 0 20rpx;
			margin: 20rpx 0;
		}

		.one-s-yc>view:nth-child(1) {
			font-size: 28rpx;
			font-weight: bold;
		}

		.one-s-yc>view:nth-child(2) {
			font-size: 24rpx;
			color: #4c4d4d;
			margin-top: 10rpx;
		}

		.key-bord {
			background: #ededed;
			padding: 20rpx 0;
			padding-bottom: 70rpx;

			.one-letter {
				background: #ffffff;
				color: #5b5b5b;
				width: 56rpx;
				height: 70rpx;
				border-radius: 10rpx;
				margin: 10rpx 10rpx;
			}

			.delet-icon {
				position: absolute;
				right: 32rpx;
				background: #ffffff;
				color: #5b5b5b;
				width: 82rpx;
				height: 70rpx;
				border-radius: 10rpx;

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}

		.keyboard-type {
			width: 100%;
			justify-content: flex-end;
		}

		.keyboard-type-list {
			background: #f5f6f9;
			border-radius: 20rpx 20rpx 0 0;
			overflow: hidden;

		}

		.one-keyboard-type {
			font-size: 28rpx;
			width: 170rpx;
			height: 70rpx;
			border-radius: 20rpx 20rpx 0 0;
			color: #7d7e7f;
		}

		.sel-type {
			background: #fff;
			box-shadow: 0 0 4px 2px #dcdcdc;
			color: #000;
		}

		.yc-changyong {
			font-size: 24rpx;
			background: #f5f6f9;
			border-radius: 100rpx;
			margin: 20rpx;
			width: fit-content;
			padding: 0 20rpx;
			height: 59rpx;
			min-width: 100rpx;
			margin-bottom: 0;
		}

		.jisu-keyboard {
			background: #fff;
			width: 90%;
			font-size: 28rpx;
			margin: 20rpx 0;
			height: 70rpx;
			padding: 0 20rpx;
			border-radius: 10rpx;
		}
	}

	.input-line {
		color: #bab7bb;
		animation: dropdown 1s linear infinite;
		font-size: 40rpx;
	}

	@keyframes dropdown {
		0% {
			display: none;
			opacity: 0;
		}

		50% {
			display: flex;
			opacity: 1;
		}
	}

	.yc-noinfo {
		font-size: 32rpx;
	}

	.top-box {
		background: #fff;
		justify-content: flex-end;
		padding-bottom: 20rpx;
		position: fixed;
		top: var(--window-top);
		left: 0;
		z-index: 9;
	}

	.submit-btn {
		font-weight: bold;
		margin-top: 20rpx;
		font-size: 32rpx;
		margin-right: 20rpx;
		color: #fff;
		height: 62rpx;
		width: 120rpx;
		border-radius: 10rpx;
	}
</style>